{extend name="base/base" /}
{block name="title"}权限管理{/block}
{block name="content"}

<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span
                class="c-gray en">&gt;</span> 权限管理 <a class="btn btn-success radius r"
                                                      style="line-height:1.6em;margin-top:3px"
                                                      href="javascript:location.replace(location.href);" title="刷新"><i
                    class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="cl pd-5 bg-1 bk-gray">
                <span class="l">  <a class="btn btn-primary radius" href="/admin/authrule/create">
                        <i class="Hui-iconfont">&#xe600;</i> 添加顶级权限</a> </span>
                <span class="l">  <a class="btn btn-primary radius" href="/admin/authrule/onekeycreate">
                        <i class="Hui-iconfont">&#xe600;</i> 一键添加权限规则</a> </span>
            </div>

            <div class="mt-10">
                <table class="table table-border table-bordered table-hover table-bg">
                    <thead>
                    <tr>
                        <th scope="col" colspan="6">权限管理</th>
                    </tr>
                    <tr class="text-c">
                        <th width="40">ID</th>
                        <th width="200">权限名</th>
                        <th width="300">权限规则（模块/控制器/方法）</th>
                        <th width="70">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="treeDatas" id="ruleData"}
                    <tr>
                        <td class="text-c">{$ruleData.id}</td>
                        <td>{$ruleData._name}</td>
                        <td>{$ruleData.name}</td>
                        <td class="text-c">
                            <button onclick="addAuthModal({$ruleData.id})" class="btn btn-sm btn-warning">添加子权限</button>
                            <a title="编辑" href="/admin/authrule/{$ruleData.id}/edit"
                               style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i>
                            </a>
                            <a title="删除" href="javascript:;" onclick="deleteauthrule({$ruleData.id});"
                               class="ml-5"
                               style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i>
                            </a>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
        </article>
    </div>

    <script src="https://cdn.bootcss.com/jquery/2.1.0/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
    <!--子权限-->
    <style>
        input[type="text"] {
            border: 1px solid #EEEEEE;
            padding: 10px;
        }
    </style>
    <!--模态框-->
    <div class="modal fade" id="addAuthModal" tabindex="-1" role="dialog" aria-labelledby="addAuthModal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="addAuthModal">添加子权限</h4>
                </div>
                <form action="/admin/authrule" method="post">
                    <div class="modal-body">
                        <input type="hidden" name="pid" id="pid" value="">
                        <div class="form-group">
                            <label for="title" class="control-label">权限名</label>
                            <input type="text" class="form-control" id="title" placeholder="请输入权限名称" name="title">
                        </div>
                        <div class="form-group">
                            <label for="name" class="control-label">权限规则(模块/控制器/方法):</label>
                            <input required id="name" class="form-control" type="text" placeholder="权限规则(模块/控制器/方法)"
                                   name="name">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">确认</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script>
        function addAuthModal(id) {
            $('#pid').val(id);
            $('#title').val('');
            $('#name').val('');
            $('#addAuthModal').modal();
        }
    </script>

    <!--删除-->
    <script>
        function deleteauthrule(id) {
            if (!confirm('确认操作，此操作不可逆?')) {
                return;
            }
            $.ajax({
                    type: "DELETE", //提交方式
                    url: "/admin/authrule/" + id,//路径
                    dataType: 'Json',
                    success: function (res) {
                        if (res.status == 1) {
                            alert(res.msg);
                            location.reload()
                        } else {
                            alert(res.msg);
                        }
                    }
                }
            )
        }
    </script>
</section>
{/block}